package servlet;

import com.alibaba.fastjson.JSON;
import pojo.Standards;
import service.StandardsService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * 获取所有票价标准记录
 * 无输入，直接查询所有票价标准记录standards后返回List<standards>
 */
@WebServlet("/standardsServlet")
public class StandardsServlet extends HttpServlet {
    private final StandardsService service = new StandardsService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Standards> standards = service.selectAllStandards();

        String jsonString = JSON.toJSONString(standards);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(jsonString);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
